
package com.Controller;

import com.Common.ResultModel;
import com.Mapper.Admin.MenuMapper;
import com.Model.Admin.Menu;
import com.Model.Admin.UserInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class IndexController {


    @Autowired
    private MenuMapper menuMappers;

    @RequestMapping(value = {"/index", "unauth"})
    public String home() {

       /* int left = 0, right = 10;
        for (int i = left, j = i; i < right; j = i++) {
            System.out.println("i--" + i);
            System.out.println("j--" + j);
        }
        for (int k = 0; k < 11; k++) {
            feePlatMqService.openAccountMsg("测试" + String.valueOf(k));
        }
        System.out.println("redirect to home page!");*/
        //  List<User> users = userService.getUser();
        //model.addAttribute("users", users);
        return "index";
    }


    @RequestMapping(value = "/admin/menu")
    @ResponseBody
    public ResultModel Menu() {
        ResultModel rt = new ResultModel();
        Session session = SecurityUtils.getSubject().getSession();
        UserInfo userInfo = (UserInfo) session.getAttribute("user");
        List<Menu> lst = menuMappers.getMenuByUser(userInfo.getUserName());
        if (CollectionUtils.isEmpty(lst)) {
            rt.setCode(-1);
            rt.setMsg("没有任何权限");
        } else {
            rt.setCode(0);
            rt.setData(lst);
        }
        return rt;
    }
}
